<%@ taglib uri="http://www.rapid-framework.org.cn/rapid" prefix="rapid"%>
<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<rapid:override name="frame-header-style">
	<link rel="stylesheet" href="resources/css/index-page.css">
</rapid:override>

<rapid:override name="frame-header-script">
	<script type="text/javascript" src="resources/js/jquery.min.js"></script>
	<script type="text/javascript" src="resources/js/jquery.min.js"></script>
	<script>
		$(function() {

			//判断标签名称是否存在
			$("#tagName").blur(tagNam);
			function tagNam() {
				var r = false;
				var reg = /^[^\s]{1,20}$/;
				if (!reg.test($("#tagName").val())) {
					$("#tagName_msg").html("标签名不合法.请输入1-20位字符");
					return r;
				}
				$.ajax({
					url : "tag/yzTagName",
					type : "POST",
					data : {
						tagName : $("#tagName").val()
					},
					async : false,
					cache : false,
					dataType : "text",
					success : function(str) {
						if (str == 0) {//没有该名字
							$("#tagName_msg").html("*");
							r = true;
						} else {
							$("#tagName_msg").html("该名称已被占用");
						}
					}
				});
				return r;
			}

			//添加
			$("#subm").click(function() {
				var r = true;
				
				if (!tagNam()) {
					r = false;
				}

				if (r) {
					r = confirm("确定修改吗");
				}
				return r;
			});


		});
	</script>
</rapid:override>

<rapid:override name="frame-content">
<div style="padding: 15px;">
	<blockquote class="layui-elem-quote">
		<span class="layui-breadcrumb" lay-separator="/"> 
			<a href="Login">首页</a> 
			<a href="tag/allTag">标签列表</a> 
			<a><cite>修改标签</cite></a>
		</span>
	</blockquote>

	<div class="layui-row">
					<div class="layui-col-md4">
				<form class="layui-form" method="post" id="myForm" action="tag/updateTag">
					<input type="hidden" name="tagId" value="${tag.tagId }" />
					<div class="layui-form-item">
						<div class="layui-input-block">
							<strong>添加标签</strong>
						</div>
						<div class="layui-input-block">
							名称 
							<span id="tagName_msg" style="color: #FF5722;">*</span>
							<input type="text" name="tagName" id="tagName" placeholder="请输入标签名称" autocomplete="off" class="layui-input" value="${tag.tagName }" required>
						</div>
						<br>
						<div class="layui-input-block">
							标签描述 
							<input type="text" name="tagDescription" placeholder="请输入标签描述" autocomplete="off" class="layui-input" value="${tag.tagDescription }" >
						</div>
						<br>
						<div class="layui-input-block">
							<button class="layui-btn" lay-filter="formDemo" type="submit" id="subm">修改</button>
							${msg }
						</div>
					</div>
				</form>
				<blockquote class="layui-elem-quote layui-quote-nm">
					温馨提示：
					<ul>
						<li>1、标签名必选，建议不要太长</li>
						<li>2、标签名勿重复</li>
					</ul>
				</blockquote>
			</div>
			
			<div class="layui-col-md8">
				<table class="layui-table">
					<colgroup>
						<col width="300">
						<col width="50">
						<col width="100">
						<col width="50">
					</colgroup>
					<thead>
						<tr>
							<th>名称</th>
							<th>文章数</th>
							<th>操作</th>
							<th>ID</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach var="t" items="${tagList }">
							<tr>
								<td>
									<a href="tag/getTagById/${t.tagId }" target="_blank">${t.tagName }</a>
								</td>
								
								<td>
									<a href="tag/getArticlesByTagId/${t.tagId }" target="_blank" lay-data="{sort:true}">${t.articleCount }</a>
								</td>
								
								<td>
									<a href="tag/edit/${t.tagId }" class="layui-btn layui-btn-mini">编辑</a>
									<c:if test="${t.articleCount==0 }">
										<a href="tag/deleteTag/${t.tagId }" class="layui-btn layui-btn-danger layui-btn-mini" onclick="return confirmDelete()">删除</a>
									</c:if>
								</td>
								
								<td>${t.tagId }</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
				<blockquote class="layui-elem-quote layui-quote-nm">
					温馨提示：
					<ul>
						<li>如果该标签包含文章，将不可删除</li>
					</ul>
				</blockquote>
			</div>
	</div>

</div>
</rapid:override>

<%@ include file="../framework.jsp" %>